<?php
class MvcPathCorrectorTest extends PHPUnit_Framework_TestCase {

    const TEST_REQUEST_CAPS                       = 'ConTroLler/MetHod/paRaM';
    const TEST_REQUEST_WHIT_GET_REQUEST           = 'controller/method/param?id=1050';
    const TEST_REQUEST_MANY_PARAMS                = 'controller/method/param/param';
    const TEST_REQUEST_WITH_STAR_END_DELIMITERS   = '/controller/method/param/';
    const TEST_REQUEST_SIMPLE_REPLACE             = 'incontroller/method/param';
    const TEST_REQUEST_REGEXP_REPLACE             = 'index/param';
    const TEST_REQUEST_INSERT_DEFAULT_METHOD      = 'controller';
    const TEST_REQUEST_AJAX                       = '/ajax/';


    /**
     * @return K_Config
     */
    private function _getConfig () {
        return new K_Config('/opt/http/fw/trunk/t/configs/MvcPathCorrectorTest.php');
    }


    /**
     * @return K_MVC_PathCorrector
     */
    private function _standartTestObject () {
        return new K_MVC_PathCorrector($this->_getConfig());
    }


    public function testConstructor_CorrectCreateObject () {
        $objPathCorrector = $this->_standartTestObject();

        $this->assertEquals('K_MVC_PathCorrector', get_class($objPathCorrector));
    }


    public function testRequestCorrect_LowerRequest () {
        $objPathCorrector = $this->_standartTestObject();

        $this->assertEquals(
            'controller/method/param',
            $objPathCorrector->requestCorrect(self::TEST_REQUEST_CAPS)
        );
    }


    public function testRequestCorrect_ClipGetRequest () {
        $objPathCorrector = $this->_standartTestObject();

        $this->assertEquals(
            'controller/method/param',
            $objPathCorrector->requestCorrect(self::TEST_REQUEST_WHIT_GET_REQUEST)
        );
    }


    public function testRequestCorrect_ManyParams () {
        $objPathCorrector = $this->_standartTestObject();

        $this->assertEquals(
            'controller/method/param/param',
            $objPathCorrector->requestCorrect(self::TEST_REQUEST_MANY_PARAMS)
        );
    }


    public function testRequestCorrect_DeletedStartEndDelimiters () {
        $objPathCorrector = $this->_standartTestObject();

        $this->assertEquals(
            'controller/method/param',
            $objPathCorrector->requestCorrect(self::TEST_REQUEST_WITH_STAR_END_DELIMITERS)
        );
    }


    public function testRequestCorrect_SimpleReplaceByRule () {
        $objPathCorrector = $this->_standartTestObject();

        $this->assertEquals(
            'outcontroller/method/param',
            $objPathCorrector->requestCorrect(self::TEST_REQUEST_SIMPLE_REPLACE)
        );
    }


    public function testRequestCorrect_RegexpReplaceByRule () {
        $objPathCorrector = $this->_standartTestObject();
        $this->assertEquals(
            'main/index/param',
            $objPathCorrector->requestCorrect(self::TEST_REQUEST_REGEXP_REPLACE)
        );
    }


    public function testRequestCorrect_InsertDefaultController () {
        $objPathCorrector = $this->_standartTestObject();

        $this->assertEquals(
            'controller/defaultmethod',
            $objPathCorrector->requestCorrect(self::TEST_REQUEST_INSERT_DEFAULT_METHOD)
        );
    }


    public function testRequestCorrect_Ajax () {
        $objPathCorrector = $this->_standartTestObject();

        $this->assertEquals(
            'ajax/defaultcontroller/defaultmethod',
            $objPathCorrector->requestCorrect(self::TEST_REQUEST_AJAX)
        );
    }

}